﻿@model PublisherManagementSystem.Models.Publisher

@{
    ViewData["Title"] = "Edit";
}

<h1>Edit</h1>

<h4>Publisher</h4>
<hr />
<div class="row">
    <div class="col-md-4">
        <form asp-action="Edit">
            <div asp-validation-summary="ModelOnly" class="text-danger"></div>
            <input type="hidden" asp-for="PublisherID" />
            <div class="form-group">
                <label asp-for="PublisherName" class="control-label"></label>
                <input asp-for="PublisherName" class="form-control" />
                <span asp-validation-for="PublisherName" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="ProvinceID" class="control-label"></label>
                <select asp-for="ProvinceID" class="form-control" asp-items="ViewBag.ProvinceID"></select>
                <span asp-validation-for="ProvinceID" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="CityID" class="control-label"></label>
                <select asp-for="CityID" class="form-control" asp-items="ViewBag.CityID"></select>
                <span asp-validation-for="CityID" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="DistrictID" class="control-label"></label>
                <select asp-for="DistrictID" class="form-control" asp-items="ViewBag.DistrictID"></select>
                <span asp-validation-for="DistrictID" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="Address" class="control-label"></label>
                <input asp-for="Address" class="form-control" />
                <span asp-validation-for="Address" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="ContactPerson" class="control-label"></label>
                <input asp-for="ContactPerson" class="form-control" />
                <span asp-validation-for="ContactPerson" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="Phone" class="control-label"></label>
                <input asp-for="Phone" class="form-control" />
                <span asp-validation-for="Phone" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="Email" class="control-label"></label>
                <input asp-for="Email" class="form-control" />
                <span asp-validation-for="Email" class="text-danger"></span>
            </div>
            <div class="form-group">
                <input type="submit" value="Save" class="btn btn-primary" />
            </div>
        </form>
    </div>
</div>

<div>
    <a asp-action="Index">Back to List</a>
</div>

@section Scripts {
    @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
$(document).ready(function() {
    // 省份选择变化时加载城市
    $('#ProvinceID').change(function() {
        var provinceId = $(this).val();
        if (provinceId) {
            $.ajax({
                url: '/Publisher/GetCitiesByProvince',
                data: { provinceId: provinceId },
                type: 'GET',
                dataType: 'json',
                success: function(cities) {
                    var options = '
<option value="">请选择城市</option>';
                    $.each(cities, function(index, city) {
                        options += '
<option value="' + city.CityID + '">' + city.CityName + '</option>';
                    });
                    $('#CityID').html(options);
                    $('#DistrictID').html('
<option value="">请先选择城市</option>');
                }
            });
        } else {
            $('#CityID').html('
<option value="">请先选择省份</option>');
            $('#DistrictID').html('
<option value="">请先选择城市</option>');
        }
    });

    // 城市选择变化时加载区县
    $('#CityID').change(function() {
        var cityId = $(this).val();
        if (cityId) {
            $.ajax({
                url: '/Publisher/GetDistrictsByCity',
                data: { cityId: cityId },
                type: 'GET',
                dataType: 'json',
                success: function(districts) {
                    var options = '
<option value="">请选择区县</option>';
                    $.each(districts, function(index, district) {
                        options += '
<option value="' + district.DistrictID + '">' + district.DistrictName + '</option>';
                    });
                    $('#DistrictID').html(options);
                }
            });
        } else {
            $('#DistrictID').html('
<option value="">请先选择城市</option>');
        }
    });
});